package 滑动;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class _1456定长子串中元音的最大数目 {

    
    public static int maxVowels(String s, int k) {
        int max = 0;
        int result = 0;
        //k=4:0,1,2
        for (int i = 0; i < k - 1; i++) {
            char c = s.charAt(i);
            if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
                result++;
            }
        }
        //3
        for (int i = k - 1; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
                result++;
            }
            max = Math.max(result, max);
            //0
            char last = s.charAt(i - k + 1);
            if (last == 'a' || last == 'e' || last == 'i' || last == 'o' || last == 'u') {
                result--;
            }
        }
        return max;
    }
    public static void main(String[] args) {
        System.out.println("1456:"+maxVowels("abciiidef", 3));

    }

    
}
